import { publicMeta, type MetaType } from '@/routes/MetaModule';

let autoImportRouters = [];

const modules = import.meta.glob(['./maps/*.route.(js|ts)', '!./maps/*ignore*'], { eager: true });

// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const path in modules) {
    const list = modules[path]['default'] || [];
    autoImportRouters = autoImportRouters.concat(list);
}

const baseRouter = [
    {
        path: '/',
        name: 'Index',
        component: () => import('@pages/Index.vue'), // 首页
        meta: {
            ...publicMeta,
            noBasePath: true,
            skeleton: true,
        },
    },
];

const errorRouter = [
    {
        path: '/error',
        alias: ['/error-tip'],
        name: 'MustInAppOpen',
        component: () => import('@pages/OpenInApp.vue'), // 本地空白页
        meta: {
            ...publicMeta,
            pageTitle: 'Please Open This Page in Kumianmei App',
            noBasePath: true,
            t: 'openInApp',
        },
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: () => import('@pages/Error.vue'), // 404
        meta: <MetaType>{
            ...publicMeta,
            pageTitle: '404 Not Found',
            keepAlive: false,
            noBasePath: true,
        },
    },
];

export default [...baseRouter, ...autoImportRouters, ...errorRouter];
